Skip to content

Bucket Sort: .NET 10, corrected algorithm and copy-per-call benchmark - #2371

Merged
vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/69957-bucket-sort-csharp
Nov 12, 2026
Merged

vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/69957-bucket-sort-csharp

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Moves the BucketSort sample to net10.0 with BenchmarkDotNet 0.15.8, MSTest 4.5.2, Microsoft.NET.Test.Sdk 18.11.0 and coverlet.collector 10.1.0. SortArray picked a bucket with array[i] / numberOfBuckets, which threw on inputs such as {100, 101}, negatives and empty arrays and put almost every value into one bucket; it now scales each value's distance from the minimum to the bucket count in long arithmetic, checks the base case before reading array[0], and BubbleSort is a real neighbour-comparing bubble sort. SortArrayOptimized computes its range as a long and uses a nullable node. The benchmarks move to a separate BucketSortBenchmarks class that copies its input per call and adds an Array.Sort baseline, Program.cs passes args to BenchmarkRunner, and the tests cover edge cases, the full int range and a seeded random array against Array.Sort.

…per-call benchmark

Targets net10.0 with BenchmarkDotNet 0.15.8 and MSTest 4.5.2. SortArray now scales each value's distance from the minimum to the bucket count with long arithmetic and checks the base case first; BubbleSort compares neighbours; SortArrayOptimized uses a long range and a nullable node. The benchmark moves to BucketSortBenchmarks, copies its input per call and adds an Array.Sort baseline. New edge-case, full-range and random tests.
@vladimir-pecanac-main
vladimir-pecanac-main merged commit e347c21 into CodeMazeBlog:main Nov 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant